package com.boho.system.action;


             
/**
 * 
 *
 * @File name:  UpdateTSysUserAction.java   修改【系统后台用户:T_USER】
 * @Create on:  2010-05-10 11:27:203
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
        


            
import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.exception.UserOperationException;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.service.MessageService;

import com.boho.estates.po.TPersonnalPO;
import com.boho.system.service.UserService;


            
        
public class UpdateTSysUserAction extends ActionImp {
	
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		if (!(ex instanceof UserOperationException)) {
			atx.setErrorContext("BOHO_COMMON_1002", MessageService.getMessage("BOHO_COMMON_1002"),"【系统后台用户】" ,ex);
		}
	}
	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		Integer userid = atx.getIntegerValue("USER_ID",0);
		String username = atx.getStringValue("USER_NAME").trim();
		String phone = atx.getStringValue("PHONE","").trim();
		String email = atx.getStringValue("EMAIL","").trim();
		String remark = atx.getStringValue("REMARK","").trim();
		UserService.updateUserByPK(atx, username, phone, email, remark, userid);
		
		Integer personId = atx.getIntegerValue("PERSON_ID",null);
		TPersonnalPO conditionPO = new TPersonnalPO();
		TPersonnalPO valuePO = new TPersonnalPO();
		conditionPO.setPersonnalNo(personId);
		valuePO.setSysUserID(Integer.valueOf(userid));
		POUtils.update(atx.getConection(), conditionPO, valuePO, false);
		
		Integer oldPersonId = atx.getIntegerValue("OLD_PERSON_ID",null);
		if(oldPersonId != null && oldPersonId != personId){
			TPersonnalPO conditionPO1 = new TPersonnalPO();
			TPersonnalPO valuePO1 = new TPersonnalPO();
			conditionPO1.setPersonnalNo(oldPersonId);
			valuePO1.setSysUserID(0);
			POUtils.update(atx.getConection(), conditionPO1, valuePO1, false);
		}
		return 1;
	}
	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		return 1;
	}
}
